
var   eq;
/**
 * 初始化页面
 */

$(function(){
	initData();
	initEqView();
	
})
function initEqView(){
	queryResources();
}
function initData(){
	 eq=[];
	 for (var i = 0; i < strategyAndEq.length; i++) {
		 eq.push(""+ strategyAndEq[i].resourceId);
	}
	 
}
function  queryResources(){
	var  rname=$("#resourceName").val();
	var plan =[{code:'rID',name:'checkBox',width:10},
	           {code:'resourceIp',name:'设备IP'},
	           {code:'resourceName',name:'名称'},
	           {code:'modelName',name:'设备类型'},
	           {code:'account',name:'账户名'},
	           {code:'collectIp',name:'采集器IP'},
	           {code:'propocal',name:'采集协议'}         
	           ];	
	 var  parm={url:basePath+'/radar/strategy/getEquipmentList.do',divID:'eq',afterQuery:'afterselect'};// 常规参数
	 var  data={resourceName:rname,typeEq:type};    // 赛选条件
     easyQuery(plan,parm,data);	
     
   
}

function  afterselect(){
	  for (var i = 0; i < eq.length; i++) {
		  $("input[type='checkbox'][nodeId='"+eq[i]+"']").prop("checked", true);
	}
}

// 保存绑定的设备
function saveBundingEquip(){
     var checkBox='';
	for (var i = 0; i < eq.length; i++) {
		checkBox=checkBox+eq[i]+',';
	}
	checkBox=checkBox.substring(0,(checkBox.length-1));

	$.ajax({
		url:basePath+"/radar/strategy/saveBundingEquip.do",
	  	type:"post",
	  	dataType:"json",
	    data:{
		    "strategyId":strategyId,
		    "eq":checkBox,
		    "resourceType":type
       },
       success: function(result){
    	   var result = result.data;
    	   parent.reQuery("equipment");
    	   if(result.indexOf("success")==0){
    		   layer.msg('保存成功！', {icon : 1});
    		
    		   closeWindow();
    	   }else{
    		   layer.msg('保存失败！'); 
    		   closeWindow();
    	   }
       }
	});
}

function    manucheck(f){
     var id=$(f).attr("nodeId");
     if($(f).attr('checked')){
    	 eq.push(id);
     }else{
    	 var index = eq.indexOf(id);
    	 if (index > -1) {
    		 eq.splice(index, 1);
     }
	}
     }

	

/**复选框全选后操作
 * @param f
 */
function afterSelectAll(f){	
	 var divID=$(f).attr("divID");
	 $("input[type='checkbox'][divID='"+divID+"'][nodeId]").each(function (){
		 var index = eq.indexOf($(this).attr("nodeId"));
		 if($(f).attr('checked')){
			 //判断数组中是否含有  不含有再添加			
	    	 if (index == -1) {
	    		 eq.push($(this).attr("nodeId"));
	          }			
	     }else{	    	
	    	 if (index > -1) {
	    		 eq.splice(index, 1);
	          }
		} 
	 });   
}

